<!--#include file="utf-8.asp"-->
<!--#include file="conn.asp"-->
<!--#include file="seeion.asp"-->
<!--#include file="page.asp"-->
<!--#include file="sqlerr.asp" -->

<script language="javascript">
function showUploadDialog(s_Type, s_Link, s_Thumbnail){
var arr = showModalDialog("eWebEditor/dialog/i_upload.htm?style=popup&type="+s_Type+"&link="+s_Link+"&thumbnail="+s_Thumbnail, window, "dialogWidth:0px;dialogHeight:0px;help:no;scroll:no;status:no");}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="images/style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td class="head"><strong>添加广告</strong></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"  class="head_chile">
      <tr>
        <td width="28%">广告标题</td>
        <td width="28%">广告图片路径</td>
        <td width="28%">广告超链接</td>
        <td width="5%" align="center">排序</td>
        <td width="10%" align="center">操作</td>
      </tr>
    </table>
    
<form action="Manage_AD1.asp?type=add&Sortid=<%=request.QueryString("Sortid")%>" method="post" name="form" id="form">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="28%" height="30">
        	<input name="Title" type="name" class="textbox" id="Title" />
        	<input name="SortID" type="hidden" id="SortID" value="<%=request.QueryString("Sortid")%>"/></td>
        <td width="28%" height="30">
            <input name="pic_url" type="text" class="textbox" id="pic_url" />
            <input type="button" value="上传" onclick="showUploadDialog('image', 'form.pic_url', '')" /></td>
        <td width="28%" height="30"><input name="link_url" type="text" class="textbox" id="link_url" value="http://" /></td>
        <td width="5%" align="center"><input name="ordersID" type="text" class="textbox" id="ordersID" value="1" size="2" /></td>
        <td width="10%" height="30" align="center"><input name="button2" type="submit" class="button_01" id="button2" value="添加广告" /></td>
    </tr>
</table>
</form>
      
      </td>
  </tr>
</table>
<br />
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="head"><strong>广告管理</strong></td>
</tr>
<tr>
<td>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="head_chile">
<tr>
<td width="28%">广告标题</td>
<td width="28%">广告图片路径</td>
<td width="28%">&nbsp;广告超链接</td>
<td width="5%" align="center">排序</td>
<td width="5%" align="center">修改</td>
<td width="5%" align="center">删除</td>
</tr>
</table>
<%	
set rs=server.createobject("adodb.recordset") 
exec="select * from ad1 where sortid="& request.QueryString("Sortid") &"  order by ordersid asc" 
'response.write (exec)
'response.end
rs.open exec,conn,1,1 
if rs.eof then
response.Write "&nbsp;暂无广告！"
else
rs.PageSize =20 '每页记录条数
iCount=rs.RecordCount '记录总数
iPageSize=rs.PageSize
maxpage=rs.PageCount 
page=request("page")
if Not IsNumeric(page) or page="" then
page=1
else
page=cint(page)
end if
if page<1 then
page=1
elseif  page>maxpage then
page=maxpage
end if
rs.AbsolutePage=Page
if page=maxpage then
x=iCount-(maxpage-1)*iPageSize
else
x=iPageSize
end if	
%>
<%For i=1 To x%>
<form action="Manage_AD1.asp?type=update&Sortid=<%=request.QueryString("Sortid")%>" method="post" name="form<%=i%>" >
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td width="28%" height="30">
                <input name="Title" type="text" class="textbox" id="Title" value="<%=rs("Title")%>">
                <input name="ID" type="hidden" id="ID" value="<%=rs("ID")%>"/>
                <input name="SortID" type="hidden" id="SortID" value="<%=rs("Sortid")%>"/>
            </td>
            <td width="28%" height="30"><input name="pic_url" type=text class="textbox" id="pic_url" value="<%=rs("pic_url")%>" /></td>
            <td width="28%" height="30"><input name="link_url" type="text" class="textbox" id="link_url" value="<%=rs("link_url")%>" /></td>
            <td width="5%" align="center"><input name="ordersID" type="text" class="textbox" id="ordersID" value="<%=rs("OrdersID")%>" size="2" /></td>
            <td width="5%" height="30" align="center"><a href="javascript:this.form<%=i%>.submit();">修改</a></td>
            <td width="5%" height="30" align="center"><a href="javascript:if(confirm('确定删除？删除后不可恢复!')){window.location.href='Manage_AD1.asp?type=del&amp;id=<%=rs("id")%>&amp;sortid=<%=request.QueryString("Sortid")%>';}else{history.go(0);}">删除</a> </td>
        </tr>
    </table>
</form>


<%rs.movenext
next
%>
<%end if%>
<br />
<%'以下显示分页
call PageControl(iCount,maxpage,page,"border=0 align=center","<p align=center>")
rs.close
set rs=nothing
%></td>
</tr>
</table>
<br>
</body>
</html>

<% 
if Request.QueryString("type")="update" then

	id=request("id") 
	SortID=request.form("SortID")
	ordersID=request.form("ordersID")
	Title=request.form("Title")
	pic_url=request.form("pic_url")
	link_url=request.form("link_url")

	sql="select * from ad1 where id="&id 
	set rs=server.CreateObject("adodb.recordset")
	rs.open sql,conn,1,3
	
	IF not isNumeric(request("ordersID")) then
		response.write("<script>alert(""排序ID必须为数字！""); history.go(-1);</script>")
		response.end
	end if
	
		rs("SortID")=SortID
		rs("ordersID")=ordersID
		rs("Title")=Title
		rs("pic_url")=pic_url
		rs("link_url")=link_url
	rs.update 
	
	rs.close
	set rs=nothing
	conn.close
	set rs=nothing
	response.Write("<script language=""javascript"">alert(""修改广告成功！"");window.location.href='Manage_AD1.asp?Sortid="& SortID &"';</script>")
	end if
%> 

<%
if Request.QueryString("type")="add" then

	set rs=server.createobject("adodb.recordset")
	sql="select * from ad1"
	rs.open sql,conn,1,3
	
	SortID=request.form("SortID")
	ordersID=request.form("ordersID")
	Title=request.form("Title")
	pic_url=request.form("pic_url")
	link_url=request.form("link_url")
	
	IF not isNumeric(request("ordersID")) then
		response.write("<script>alert(""排序ID必须为数字！""); history.go(-1);</script>")
		response.end
	end if
	
'	response.write (ordersID) & "<br>"
'	response.write (Title) & "<br>"
'	response.write (pic_url) & "<br>"
'	response.write (link_url) & "<br>"
	'response.end
	
	rs.addnew
		rs("SortID")=SortID
		rs("ordersID")=ordersID
		rs("Title")=Title
		rs("pic_url")=pic_url
		rs("link_url")=link_url
	rs.update
	
	rs.close
	set rs=nothing
	conn.close
	set rs=nothing
	
	Response.Write "<script>alert('添加广告成功！');window.location.href='Manage_AD1.asp?Sortid="& SortID &"';</script>" 
end if
%>

<%
if request("type")="del" then

	id=request("id")
	SortID=request.QueryString("SortID")
	
	if id="" then
		Response.Write "<script language='javascript'>alert('参数错误!');document.location.href('Manage_AD1.asp?Sortid="& SortID &"');</script>"
		Response.End()
	end if
	
	sql="Select * from ad1 where id="&Request("id")
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,3
	
	if rs.bof and rs.eof then
		Response.Write "<script language='javascript'>alert('数据库中没有该记录！');document.location.href('Manage_AD1.asp?Sortid="& SortID &"');</script>"
		Response.End()
	else
		rs.Delete
		rs.Update
		
		rs.close
		set rs=nothing
		conn.close
		set rs=nothing
		
		Response.Write "<script language='javascript'>alert('成功删除指定的信息！');document.location.href('Manage_AD1.asp?Sortid="& SortID &"');</script>"
	end if
end if
%>

